17. Securing it All Together
Securing it All Together
QUESTION:
We wouldn’t want a user to upload a giant photo that fills up our entire space quota in Firebase Storage. Let’s add a storage security rule in the Firebase console that validates what images a user is allowed to upload in the app.
Use the examples we explored and the Firebase Storage Security documentation to design a rule that allows data to be written to storage if it is less than 3 MB.
service firebase.storage {
match /b/<firebase-bucket> /o {
match /{imageId} {
[WHAT RULE WOULD GO HERE?]
}
}
}
ANSWER:
Here is an example rule that allows you to write to storage if the data is less than 3 MB.
service firebase.storage {
match /b/<firebase-bucket> /o {
match /{imageId} {
allow write: if request.resource.size < 3 * 1024 * 1024
}
}
}